/**
 * @filename:StkOtherInController Feb 5, 2025
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2020 Wonder Co. Ltd.
 * All right reserved.
 */
package com.wonder.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vtuzx.core.utils.VtuzxUtil;
import com.wonder.admin.domain.SysAdmin;
import com.wonder.admin.service.SysAdminService;
import com.wonder.app.domain.PrdInstock;
import com.wonder.app.domain.PrdReturn;
import com.wonder.app.request.PrdInstockRequest;
import com.wonder.app.request.PrdReturnRequest;
import com.wonder.app.service.PrdInstockService;
import com.wonder.app.service.PrdReturnService;
import com.wonder.common.common.AjaxMap;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.framework.authorization.CheckAdminToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "生产入库单")
@RestController
@RequestMapping("/app/PrdInstock")
public class PrdInstockController {

@Autowired
private PrdInstockService prdInstockService;

    @Autowired
    private SysAdminService adminService;

    @Autowired
    private CheckAdminToken checkAdminToken;

    @ApiOperation(value = "生产入库单列表")
    @RequestMapping(value = "/index", method = RequestMethod.POST)
    public Map<String,Object> index(@RequestBody PrdInstockRequest prdInstockRequest) {
        Page<PrdInstock> page = new Page<PrdInstock>(prdInstockRequest.getPage(), prdInstockRequest.getLimit());
        IPage<PrdInstock> list = prdInstockService.selectList(prdInstockRequest, page);
        Map<String,Object> retMap=new HashMap<>();
        retMap.put("data", CommonPage.restPage(list));
        return AjaxMap.success(retMap);
    }
    /**
     * @explain 查看对象明细
     * @param   map 对象参数：id
     * @return  JsonResult
     * @author  Wonder
     */
    @ApiOperation(value = "查询prdinstock明细")
    @ResponseBody
    @PostMapping(value = "/prdinstockdetail")

    public AjaxResult<Map<String,Object>> getPrdInstockDetail(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception{
        if (null == map){
            return AjaxResult.failed("system.parameterError");
        }
        Map<String,Object> data = prdInstockService.getPrdInstockDetail(map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }
    }
    @ApiOperation(value = "生产入库单明细(手机端)")
    @RequestMapping(value = "/get_prd_instock_detail", method = RequestMethod.POST)
    public AjaxResult<Map<String,Object>> getOptrptisDetail(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();
        Map<String,Object> data = prdInstockService.getprdinstockde(user_id,map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }

    }


    @ApiOperation(value = "库管生产入库明细接口(手机端)")
    @RequestMapping(value = "/get_prd_instock_detail_ku", method = RequestMethod.POST)
    public AjaxResult<Map<String,Object>> getOptrptisDetailKu(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();
        Map<String,Object> data = prdInstockService.getprdinstockdeKu(user_id,map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }

    }

    @ApiOperation(value = "合托的查询入库明细")
    @RequestMapping(value = "/get_prd_instock_detail_ku_merge", method = RequestMethod.POST)
    public AjaxResult<Map<String,Object>> getprdinstockdeKuMerge(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();
        Map<String,Object> data = prdInstockService.getprdinstockdeKuMerge(user_id,map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }

    }

    @ApiOperation(value = "生产入库列表(手机端)")
    @RequestMapping(value = "/get_proinstock_list", method = RequestMethod.POST)
    public AjaxResult<Map<String,Object>> getProInstocklist(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);

        Map<String,Object> data = prdInstockService.getProInstocklist(user,map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }

    }
    @ApiOperation(value = "生产入库列表质检(手机端)")
    @RequestMapping(value = "/get_proinstock_list_quality", method = RequestMethod.POST)
    public AjaxResult<Map<String,Object>> getProInstocklistQuality(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);

        Map<String,Object> data = prdInstockService.getProInstocklistQuality(user,map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }

    }


    @ApiOperation(value = "质检生产入库单")
    @RequestMapping(value = "/audit_prd_inspect", method = RequestMethod.POST)
    public AjaxResult<?> auditPrdInspect(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();

        Boolean res = prdInstockService.auditPrdInspect(user_id,userName,map);
        if (res){
            return AjaxResult.success(res);
        } else {
            return AjaxResult.failed();
        }

    }


    @ApiOperation(value = "审核生产入库单")
    @RequestMapping(value = "/audit_prd_in", method = RequestMethod.POST)
    public AjaxResult<?> auditPrdIn(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();

        Boolean res = prdInstockService.auditPrdIn(user_id,userName,map);
        if (res){
            return AjaxResult.success(res);
        } else {
            return AjaxResult.failed();
        }

    }

    /**
     * @explain 根据托号查询入库单信息(合托用)
     * @param   map 对象参数：id
     * @return  JsonResult
     * @author  Wonder
     */
    @ApiOperation(value = "根据托号查询入库单信息(合托用)")
    @ResponseBody
    @PostMapping(value = "/get_in_stock_by_tray")

    public AjaxResult<Map<String,Object>> getInStockByTray(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception{
        if (null == map){
            return AjaxResult.failed("system.parameterError");
        }
        Map<String,Object> data = prdInstockService.getInStockByTray(map);
        if (null != data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }
    }

    /**
     * @explain 删除合托的信息
     * @param   map 对象参数：id
     * @return  JsonResult
     * @author  Wonder
     */
    @ApiOperation(value = "删除合托的信息")
    @ResponseBody
    @PostMapping(value = "/delete_merge")

    public AjaxResult<?> deleteMerge(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception{
        if (null == map){
            return AjaxResult.failed("system.parameterError");
        }
        Boolean data = prdInstockService.deleteMerge(map);
        if ( data){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }
    }


    /**
     * @explain 合并托盘
     * @param   map 对象参数：id
     * @return  JsonResult
     * @author  Wonder
     */
    @ApiOperation(value = "合并托盘")
    @ResponseBody
    @PostMapping(value = "/merge_tray_pda")

    public AjaxResult<?> mergeTrayPda(HttpServletRequest request, @RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();
        Map<String,Object> data  = prdInstockService.mergeTrayPda(userName,map);
        if ( !VtuzxUtil.isEmpty(data)){
            return AjaxResult.success(data);
        } else {
            return AjaxResult.failed();
        }
    }

    @ApiOperation(value = "审核生产入库单(托码合并的)")
    @RequestMapping(value = "/audit_prd_in_merge", method = RequestMethod.POST)
    public AjaxResult<?> auditPrdInMerge(HttpServletRequest request,@RequestBody Map<String,Object> map) throws Exception{
        String token = checkAdminToken.getTokenFormRequest(request);
        SysAdmin user = adminService.getAdminByToken(token);
        String userName = user.getName();
        Long user_id = user.getUser_id();

        Boolean res = prdInstockService.auditPrdInMerge(user_id,userName,map);
        if (res){
            return AjaxResult.success(res);
        } else {
            return AjaxResult.failed();
        }

    }
}
